package com.payment.service;

import com.alipay.v3.ApiException;
import com.alipay.v3.model.AlipayTradeFastpayRefundQueryResponseModel;
import com.alipay.v3.model.AlipayTradeQueryResponseModel;
import com.alipay.v3.model.AlipayTradeRefundResponseModel;
import com.alipay.v3.model.GoodsDetail;
import com.aliyun.pojo.pay.AliyunPayRefundParam;
import com.payment.domain.vo.ZfbCallbackVo;
import com.payment.service.impl.ZfbPaymentServiceImpl;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.math.BigDecimal;

@Service
public class PaymentServiceFactory implements ApplicationContextAware {

    ApplicationContext applicationContext;

    public String payment(String out_trade_no, BigDecimal total_amount, String subject, GoodsDetail[] goodsDetails) {
        return applicationContext.getBean("zfb-payment-service", ZfbPaymentServiceImpl.class).payment(out_trade_no, total_amount, subject, goodsDetails);
    }

    public ZfbCallbackVo callback(HttpServletRequest request, HttpServletResponse response) throws IOException, ApiException {
        return applicationContext.getBean("zfb-payment-service", ZfbPaymentServiceImpl.class).callback(request, response);
    }

    public AlipayTradeQueryResponseModel queryTrade(String out_trade_no,String trade_no) {
        return applicationContext.getBean("zfb-payment-service", ZfbPaymentServiceImpl.class).queryTrade(out_trade_no,trade_no);
    }

    public String queryTradeNo(String out_trade_no) {
        return applicationContext.getBean("zfb-payment-service", ZfbPaymentServiceImpl.class).queryTradeNo(out_trade_no);
    }

    public String queryTradeStatus(String out_trade_no, String trade_no) {
        return applicationContext.getBean("zfb-payment-service", ZfbPaymentServiceImpl.class).queryTradeStatus(out_trade_no, trade_no);
    }

    public String cancel(String out_trade_no, String trade_no) {
        return applicationContext.getBean("zfb-payment-service", ZfbPaymentServiceImpl.class).cancel(out_trade_no, trade_no);
    }

    public AlipayTradeRefundResponseModel refund(AliyunPayRefundParam aliyunPayRefundParam) {
        return applicationContext.getBean("zfb-payment-service", ZfbPaymentServiceImpl.class).refund(aliyunPayRefundParam);
    }
    public AlipayTradeFastpayRefundQueryResponseModel queryRefund(String out_request_no, String out_trade_no, String trade_no) {
        return applicationContext.getBean("zfb-payment-service", ZfbPaymentServiceImpl.class).queryRefund(out_request_no, out_trade_no, trade_no);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
